{include file="public/header" /}
<style>
    .layui-copy{width: 30px;position:absolute;top:1px;bottom: 1px;right:1px;cursor:pointer;background:white;text-align: center;color: #999999c2;display: flex;align-items: center;justify-content: center;}
    .layui-copy:hover{color: #999999;}
</style>
<body class="gray-bg">
<div class="wrapper wrapper-content">
    <!-- Panel Other -->
    <div class="ibox float-e-margins">
        <div class="ibox-title">
            <h5>业务员提现列表</h5>
            <div class="ibox-tools">
                <a class="collapse-link">
                    <i class="fa fa-chevron-up"></i>
                </a>
            </div>
        </div>
        <div class="ibox-content">
            <div class="row">
                <!--搜索框开始-->
                <div class="col-sm-12">
                    <div class="collapse" id="searchBox">
                        <div class="layui-form layui-form-item">
                            <div class="layui-col-md6 layui-input-inline">
                                <input type="text" id="key" class="layui-input search" name="key" value="" placeholder="提现人名称/流水号" />
                            </div>
                            <div class="layui-input-inline">
                                <button class="layui-btn" lay-submit="" lay-filter="LAY-search">立即搜索</button>
                                <button  class="layui-btn layui-btn-normal" id="empty"  lay-submit="" lay-filter="LAY-search">重置</button>
                            </div>
                        </div>
                    </div>
                </div>
                <!--搜索框结束-->
                <!--操作框开始-->
                <div class="col-sm-12">
                    <div class="input-group pull-left" >
                        <a href="javascript:;" onclick="tableReload()" class="btn btn-success" data-toggle="tooltip" title="" data-original-title="刷新表格" data-placement="auto">
                            <i class="fa fa-refresh"></i>
                        </a>
                        <button  class="btn btn-danger m-l-xs" href="javascript:;" data-toggle="dropdown">
                            <i class="fa fa-wrench"></i> 批量操作 <span class="caret"></span>
                        </button>
                        <ul class="dropdown-menu animated fadeInDown" role="menu">
                            <li><a href="javascript:;" class="layuiBtn" data-type="getCheckData"><i class="fa fa-credit-card"></i> 批量提现 </a></li>
                        </ul>
                    </div>
                    <div class="input-group pull-right" data-toggle="tooltip" title="" data-original-title="搜索">
                        <button class="btn btn-primary" data-toggle="collapse"
                                data-target="#searchBox" >
                            <i class="glyphicon glyphicon-search"></i>
                        </button>
                    </div>
                </div>
                <!--操作框结束-->
            </div>
            <div class="hr-line-dashed"></div>

            <div class="example-wrap">
                <div class="example">
                    <table class="layui-hide" id="test" lay-filter="demo"></table>
                    <!--提现状态模板-->
                    <script type="text/html" id="titleTpl">
                        {{# if(d.r_status == 1){ }}
                        <span class="layui-badge layui-bg-orange">待审核</span>
                        {{# }else if(d.r_status == 2){ }}
                        <span class="layui-badge layui-bg-green">已到账</span>
                        {{# }else if(d.r_status == 3){ }}
                        <span class="layui-badge">拒绝</span>
                        {{# } }}
                    </script>
                    <script type="text/html" id="sheTpl">
                        {{# if(d.r_where == 1){ }}
                        银行卡
                        {{# }else if(d.r_where == 2){ }}
                        支付宝
                        {{# }else if(d.r_where == 3){ }}
                        微信
                        {{# } }}
                    </script>
                    <!--操作模板-->

                    <script type="text/html" id="opeBar">
                        {{# if(d.r_status == 1){ }}
                        <a href="javascript:;" onclick="agreeshop('{{d.r_id}}')" class="btn btn-primary btn-xs m-r-xs" title="审核提现"><i class="fa fa-pencil"></i></a>
                        {{# } }}
                    </script>
                </div>
            </div>
        </div>
    </div>
</div>
{include file="public/footer" /}
<script>
    //layui渲染数据表格
    layui.use('table', function () {
        var table = layui.table
            , form = layui.form;
        table.render({
            elem: '#test'
            , url: '{:url("Money/salesmanMoney")}'
            , page: true
            , even: false //开启隔行背景
            , size: 'lg' //sm小尺寸的表格 lg大尺寸
            // ,width:100
            , cellMinWidth: 150
            , limits: [5, 10, 15, 20, 25, 30]
            , limit: "{:config('pages')}"
            , loading: true
            , id: 'testReload'
            , cols: [[
                {type:'checkbox', width: 60, fixed:'left'}
                , {type:'numbers', width: 80, title: '序号'}
                , {field: 'r_id', width: 80, title: 'ID', align: 'center'}
                , {field: 'user_name', width: 220, title: '提现人', align: 'center',templet:"<div><div style='position: relative;'><input type='text' class='layui-input' value='{{d.user_name}}' readonly><div class='layui-copy' onclick='wk.lay_copy(this)' title='复制' alt='复制'><span><i class='fa fa-paste'></i></span></div></div></div>"}
                , {field: 'r_money', width: '', title: '提现金额', align: 'center'}
                , {field: 'r_acc_bank', width: 220, title: '开户行', align: 'center',templet:"<div><div style='position: relative;'><input type='text' class='layui-input' value='{{d.r_acc_bank}}' readonly><div class='layui-copy' onclick='wk.lay_copy(this)' title='复制' alt='复制'><span><i class='fa fa-paste'></i></span></div></div></div>"}
                , {field: 'r_acc_num', width: 250, title: '账户/手机号', align: 'center',templet:"<div><div style='position: relative;'><input type='text' class='layui-input' value='{{d.r_acc_num}}' readonly><div class='layui-copy' onclick='wk.lay_copy(this)' title='复制' alt='复制'><span><i class='fa fa-paste'></i></span></div></div></div>"}
                , {field: 'r_where', width: '', title: '储蓄设备', align: 'center',templet:'#sheTpl'}
                , {field: 'r_water', width: 220, title: '流水号', align: 'center'}
                , {field: 'r_time', width: 200, title: '提现时间', align: 'center'}
                , {field: 'r_status', width: '', title: '状态',align: 'center', templet: '#titleTpl'}
                , {fixed: 'right', width: 100, title: '操作', align: 'center', toolbar: '#opeBar'}
            ]]
        });

        //批量操作
        var $ = layui.$, active = {
            getCheckData: function(){
                //批量提现
                layer.confirm('提现同意吗？', {
                    btn: ['同意','拒绝'] //按钮
                }, function(){
                    layer.prompt({
                        formType: 2,
                        value: ' ',
                        title: '备注',
                        area: ['800px', '350px'] //自定义文本域宽高
                    }, function(value, index, elem){
                        layer.close(index);
                        shopchange(1,getIds(),value,"{:url('shopSaleMoney')}")
                    });
                }, function(){
                    layer.prompt({
                        formType: 2,
                        value: '',
                        title: '拒绝理由',
                        area: ['800px', '350px'] //自定义文本域宽高
                    }, function(value, index, elem){
                        layer.close(index);
                        shopchange(2,getIds(),value,"{:url('shopSaleMoney')}")
                    });
                });
            }
        };
        $('.layuiBtn').on('click', function () {
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });
        var getIds = function () {
            var ids = [];
            var checkStatus = table.checkStatus('testReload')
                ,data = checkStatus.data;
            $.each(data,function(index,item){
                ids.push(item['r_id'])
            });
            return ids;
        }
    });
    function agreeshop(id){
        layer.confirm('提现同意吗？', {
            btn: ['同意','拒绝'] //按钮
        }, function(){
            layer.prompt({
                formType: 2,
                value: ' ',
                title: '备注',
                area: ['800px', '350px'] //自定义文本域宽高
            }, function(value, index, elem){
                layer.close(index);
                shopchange(1,id,value,"{:url('getSaleMoney')}")
            });
        }, function(){
            layer.prompt({
                formType: 2,
                value: '',
                title: '拒绝理由',
                area: ['800px', '350px'] //自定义文本域宽高
            }, function(value, index, elem){
                layer.close(index);
                shopchange(2,id,value,"{:url('getSaleMoney')}")
            });
        });
    }
    function shopchange(type,id,value,url){
        var value = value ? value : '';
        $.ajax({
            url:url,
            type:'post',
            data:'type='+type+'&r_id='+id + '&remark=' + value,
            dataType:'json',
            success:function(res){
                if(res.code == 200){
                    layer.msg(res.msg,{icon:1,time:1500,shade:0.1},function(index){
                        //重载当前页表格
                        $(".layui-laypage-btn").click();
                    })
                }else if(res.code == 100){
                    wk.error(res.msg,'',2);
                }
            }
        })
    }
</script>
</body>
</html>